var config = require('../../config');
var accessTokenController = require('./AccessTokenController');
var request = require('request');

module.exports.customMenu = function (callback, req) {
    var accessToken = accessTokenController.getAccessToken();
    console.log('\n\naccessToken    '+accessToken + '\n\n');
    // console.log('ready to customMenu, accessToken is : ' + accessToken);
    request({
        url: 'https://api.weixin.qq.com/cgi-bin/menu/create?access_token=' + accessToken,
        method: 'POST',
        json:{
        "button": [
            {
                "type": "view",
                "name": "推荐",
                "sub_button": [
                    {
                        "type": "view",
                        "name": "影院",
                        "url": "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxb8559b450f58c079&redirect_uri=http%3A%2F%2Fweixin.bestmovie.com.cn%2Frecommendedcinemas&response_type=code&scope=snsapi_userinfo&state=123#wechat_redirect"
                        // "url": "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxaf378ab4ba9fb3da&redirect_uri=http%3A%2F%2Fweixin.tooking.cn%2Frecommendedcinemas&response_type=code&scope=snsapi_userinfo&state=123#wechat_redirect"
                    },
                    {
                        "type": "view",
                        "name": "影片",
                        "url": "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxb8559b450f58c079&redirect_uri=http%3A%2F%2Fweixin.bestmovie.com.cn%2Frecommendedmovies&response_type=code&scope=snsapi_userinfo&state=123#wechat_redirect"
                        // "url": "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxaf378ab4ba9fb3da&redirect_uri=http%3A%2F%2Fweixin.tooking.cn%2Frecommendedmovies&response_type=code&scope=snsapi_userinfo&state=123#wechat_redirect"
                    }
                ]
            },
            {
                "type": "view",
                "name": "观影",
                "url": "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxb8559b450f58c079&redirect_uri=http%3A%2F%2Fweixin.bestmovie.com.cn%2Fscan&response_type=code&scope=snsapi_base&state=123#wechat_redirect"
                // "url": "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxaf378ab4ba9fb3da&redirect_uri=http%3A%2F%2Fweixin.tooking.cn%2Fscan&response_type=code&scope=snsapi_base&state=123#wechat_redirect"
            },
            {
                "type": "view",
                "name": "我",
                "sub_button": [
                    {
                        "type": "view",
                        "name": "个人信息",
                        "url": "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxb8559b450f58c079&redirect_uri=http%3A%2F%2Fweixin.bestmovie.com.cn%2Fusercenter&response_type=code&scope=snsapi_userinfo&state=123#wechat_redirect"
                        // "url": "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxaf378ab4ba9fb3da&redirect_uri=http%3A%2F%2Fweixin.tooking.cn%2Fusercenter&response_type=code&scope=snsapi_userinfo&state=123#wechat_redirect"
                    },
                    {
                        "type": "view",
                        "name": "我要开影院",
                        "url": "http://mp.weixin.qq.com/s/cMnVAYZr7z66yp9QnSuHfw"
                    },
                    {
                        "type": "view",
                        "name": "激活",
                        "url": "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxb8559b450f58c079&redirect_uri=http%3A%2F%2Fweixin.bestmovie.com.cn%2Fcardbinding&response_type=code&scope=snsapi_userinfo&state=123#wechat_redirect"
                        // "url": "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxaf378ab4ba9fb3da&redirect_uri=http%3A%2F%2Fweixin.tooking.cn%2Fcardbinding&response_type=code&scope=snsapi_userinfo&state=123#wechat_redirect"
                    }
                ]
            }
        ]
    }
    }, function (err, response, body) {
        if (err) {
            console.log('customMenu 请求失败');
            return;
        }
        console.log('customMenu 请求成功： ', body);
        callback();
    })
};



